#include "KUdpSocket.h"
#include "KDef.h"

bool KUdpSocket::getRemoteAddress(KIpAddress &addrRemote) const
{
    addrRemote.reset(m_addrFrom);
    return true;
}

bool KUdpSocket::asyncRecv(LPWSABUF pBuf, LPOVERLAPPED request)
{
    DWORD flags = 0;
    return WSARecvFrom(handle(), pBuf, 1, NULL, &flags,
        m_addrFrom.name(), m_addrFrom.pLength(), request, NULL) != SOCKET_ERROR;
}

bool KUdpSocket::asyncSend(LPWSABUF pBuf, LPOVERLAPPED request)
{
    KDef::IoRequest *r = static_cast<KDef::IoRequest *>(request);
    return WSASendTo(handle(), pBuf, 1, NULL, 0, reinterpret_cast<SOCKADDR *>(&r->addrTo),
        sizeof r->addrTo, request, NULL) != SOCKET_ERROR;
}